<?php

namespace search\controllers\bigdata;

use business\elasticsearch\services\BigDataRadarProjectService;

class RadarProjectController extends BaseController
{
    public $enableCsrfValidation = false;//csrf安全
    /**
     *
     * @api {get} /bigdata/radar-project/subscription 线索雷达推荐项目
     *
     * @apiVersion 1.0.0
     * @apiGroup bigdataDeveloper
     *
     * @apiDescription 项目订阅
     *
     * @apiParam {String} keyword                   搜索词
     * @apiParam {String} land_usage_label          土地类型
     * @apiParam {String} project_label             在建项目类型
     * @apiParam {String} fitment_fee_label         装修类型
     * @apiParam {String} start_time               开始时间
     * @apiParam {Number} end_time                 结束时间
     * @apiParam {Number} is_price_gt_avg          高端项目
     * @apiParam {Number} province_code            省份
     * @apiParam {Number} city_code                城市
     * @apiParam {String} area_code                省份和城市的复合查询，或条件，逗号拼接的
     * @apiParam {Number} page                      页码
     * @apiParam {Number} pageSize                  分页size
     *
     * @apiSuccess {Boolean} success                    返回状态
     * @apiSuccess {String}  message                    返回消息内容
     * @apiSuccess {Number}  errorCode                  错误码
     * @apiSuccess {Object}  data                       对象数组
     */
    public function actionSubscription()
    {
        try {
            $keyword = $this->getParam('keyword');//项目关键词 多选
            $landUsageLabel = $this->getParam('land_usage_label');//土地类型，多选
            $projectLabel = $this->getParam('project_label');//在建项目类型 多选
            $fitmentFeeLabel = $this->getParam('fitment_fee_label'); //装修类型，多选
            $startTime = $this->getParam('start_time');
            $endTime = $this->getParam('end_time');
            $isPriceGtAvg = $this->getParam('is_price_gt_avg'); //高端项目 多选
            $provinceCode = $this->getParam('province_code'); //省份 多选
            $cityCode = $this->getParam('city_code');//城市 多选
            $dataType = $this->getParam('data_type');//数据类型 多选
            $areaCode = $this->getParam('area_code');//省市code，多选，逗号拼接的
            $page = $this->getParam('page');
            $pageSize = $this->getParam('page_size');
            $page = intval($page) > 0 ? intval($page) : 1;
            $pageSize = intval($pageSize) > 0 ? intval($pageSize) : 100;

            $keyword = array_filter(explode(",", $keyword));
            $landUsageLabel = array_filter(explode(",", $landUsageLabel));
            $projectLabel = array_filter(explode(",", $projectLabel));
            $fitmentFeeLabel = array_filter(explode(",", $fitmentFeeLabel));
            $isPriceGtAvg = array_filter(explode(",", $isPriceGtAvg));
            $provinceCode = array_filter(explode(",", $provinceCode));
            $cityCode = array_filter(explode(",", $cityCode));
            $areaCode = array_filter(explode(",", $areaCode));
            $dataType = array_filter(explode(",", $dataType));

            $bigDataRadarProjectService = new BigDataRadarProjectService();
            $rs = $bigDataRadarProjectService->subscript(
                $keyword,
                $landUsageLabel,
                $projectLabel,
                $fitmentFeeLabel,
                $startTime,
                $endTime,
                $isPriceGtAvg,
                $provinceCode,
                $cityCode,
                $areaCode,
                $page,
                $pageSize
            );
            return $this->success($rs);

        } catch (\Exception $ex) {
            \Yii::error($ex);
            return $this->error('', '获取失败，请稍后重试');
        }
    }
}
